# Figure 6

library(tidyverse)
library(grid)

DATA         <- read.csv(file.choose(), header=TRUE)

DATA$PCT     <- DATA$PE / DATA$N
DATA$EVENT   <- factor(DATA$EVENT, levels=DATA$EVENT[1:11])
DATA$FACET   <- factor(DATA$FACET, levels=c("Serious","Clown"))

TEXT.SERIOUS <- textGrob(expression(bold("Serious")), gp=gpar(fontsize=21))
TEXT.CLOWN   <- textGrob(expression(bold("Clown"  )), gp=gpar(fontsize=21))

theme.z <- theme(
        axis.text.x        = element_text(size=15, color="black", margin=margin(t=10,r=10,b=10,l=10)),
        axis.text.x.top    = element_blank(),
        axis.text.x.bottom = element_text(size=15, color="black", margin=margin(t=10,r=10,b=10,l=10)),
        axis.text.y        = element_text(size=15, color="black", margin=margin(t=10,r=10,b=10,l=10)),
        axis.text.y.right  = element_text(size=15, color="black", margin=margin(t=10,r=10,b=10,l=10)),
        axis.ticks.x       = element_blank(),
        axis.ticks.y       = element_blank(),
        axis.title.x       = element_text(size=15, color="black", margin=margin(t= 0,r=10,b=10,l=10)),
        axis.title.y       = element_blank(),
        legend.position    = "none",
        panel.background   = element_rect(size=0.5, color="black", fill="gray90", linetype="solid"),
        panel.border       = element_rect(size=1.2, color="black", fill=NA      , linetype="solid"),
        panel.grid.major.x = element_blank(), 
        panel.grid.major.y = element_blank(),
        panel.grid.minor.x = element_blank(), 
        panel.grid.minor.y = element_blank(),
        plot.background    = element_rect(fill="white"),
        plot.caption       = element_text(size=12, hjust=0  , margin=margin(t=10)),
        plot.margin        = unit(c(t=50,r=5,b=5,l=5),"pt"),
        plot.subtitle      = element_text(size=15, hjust=0.5, margin=margin(b=7)),
        plot.title         = element_text(size=20, hjust=0.5, face="bold", margin=margin(t=0,b=35)),
        strip.background   = element_rect(color="black", fill="black"),
        strip.text.x       = element_text(size=18, color="white", face="bold", margin=margin(t=7.5,b=7.5)))

ggplot(data=DATA, aes(x=rev(as.numeric(EVENT)), y=100*PCT, fill=FACET)) +
  coord_flip(clip="off") +
scale_fill_manual(values=c("purple","orange"), breaks=c("Serious","Clown"), labels=c("Serious","Clown")) +
  geom_col(size=0.85, width=0.7, color="black") +
  scale_x_continuous(breaks=1:11, labels=rev(DATA$EVENT[1:11]), sec.axis=sec_axis(~.,breaks=1:11, labels=rev(DATA$DATE[1:11]))) +
  scale_y_continuous(limits=c(-30,30), breaks=seq(-30,30,10), labels=c("30%","20%","10%","0%","10%","20%","30%")) +
  labs(y="Percentage of all articles") +
  annotation_custom(TEXT.SERIOUS, xmin=12.75, xmax=12.75, ymin=-15, ymax=-15) + 
  annotation_custom(TEXT.CLOWN  , xmin=12.75, xmax=12.75, ymin= 15, ymax= 15) +
  theme.z

ggsave(file="Figure 6.wmf", width=8, height=6)
getwd()

